import MarkdownIt from 'markdown-it';

const mdit = new MarkdownIt({
	html: false,
	linkify: true
});
mdit.linkify.set({
	fuzzyLink: false
});
mdit.use(require('markdown-it-task-lists'))
mdit.use(require('markdown-it-link-attributes'), {
	attrs: {
		target: '_blank',
		rel: "nofollow"
	}
})
mdit.use(require('markdown-it-container'), 'spoiler', {
	validate: function (params: string) {
		return params.trim().match(/^spoiler\s+(.*)$/);
	},
	render: function (tokens: any, idx: number) {
		var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/);
		if (tokens[idx].nesting === 1) {
			// opening tag
			return '<details><summary>' + mdit.utils.escapeHtml(m[1]) + '</summary>\n';
		} else {
			// closing tag
			return '</details>\n';
		}
	}
});

export default mdit;